package com.example.myapplication;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);











    }




    // 上传安装者名称
    public static String getInstallerPackageName(Context context) {

        String pkgName = "";
        PackageManager pm = context.getPackageManager();
        pkgName = pm.getInstallerPackageName(context.getPackageName());
        return pkgName;

    }

    // 上传已安装应用名称
    public static List<String> getInstalledPackages(Context context) {

        PackageManager pm = context.getPackageManager();
        List<ApplicationInfo> applicationInfos = pm.getInstalledApplications(0);
        List<String> packageNames = new ArrayList<String>();
        //遍历所有的应用集合
        for(ApplicationInfo info : applicationInfos) {
            //获取应用的包名
            String packageName = info.packageName;
            packageNames.add(packageName);

        }
        return packageNames;
    }

//    // 上传正在运行应用名称
//    public static String getRunningPackages(Context context) {
//
//
//
//
//    }






}
